﻿//
//  Copyright (c) 2008, WebAula S/A 
//  All rights reserved.
//
//  Authors : 
//
//           * Ivan Paulovich (ivan@100loop.com)
//           Blog: http://www.100loop.com/          
//           Messenger: ivanpaulovich@hotmail.com 
//           Twitter: @ivanpaulovich
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcThemes.Models;
using Core.Domain.Model;
using Core;
using Core.Domain.Repositories;

namespace MvcThemes.Controllers
{
    public class CommentController : Controller
    {
        public ActionResult Index()
        {
            IRepository<Comment> repo = new CommentRepository();
            return View(repo.GetAll());
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Comment Comment)
        {
            IRepository<Comment> repo = new CommentRepository();
            repo.Save(Comment);
            return RedirectToAction("View", "Post", new { Id = Comment.PostId });
        }

        public ActionResult Edit(int id)
        {
            IRepository<Comment> repo = new CommentRepository();
            return View(repo.GetById(id));
        }

        [HttpPost]
        public ActionResult Edit(int id, Comment Comment)
        {
            IRepository<Comment> repo = new CommentRepository();
            repo.Update(Comment);
            return RedirectToAction("Index");
        }

        public ActionResult Delete(int id)
        {
            IRepository<Comment> repo = new CommentRepository();
            repo.Delete(repo.GetById(id));
            return RedirectToAction("Index");
        }
    }
}
